package com.mszl.blog.controller;

import com.mszl.blog.entity.ArticleBody;
import com.mszl.blog.service.ArticleBodyService;
import com.mszl.blog.vo.Result;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("articleBody")
public class ArticleBodyController {
    @Resource
    private ArticleBodyService articleBodyService;

    @GetMapping
    public ResponseEntity<Page<ArticleBody>> queryByPage(ArticleBody articleBody, PageRequest pageRequest) {
        return ResponseEntity.ok(this.articleBodyService.queryByPage(articleBody, pageRequest));
    }

    @GetMapping("{id}")
    public ResponseEntity<ArticleBody> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.articleBodyService.queryById(id));
    }

    @PostMapping
    public ResponseEntity<ArticleBody> add(@RequestBody ArticleBody articleBody) {
        return ResponseEntity.ok(this.articleBodyService.insert(articleBody));
    }

    @PutMapping("update")
    public Result edit(@RequestBody ArticleBody articleBody) {
        return Result.success(ResponseEntity.ok(this.articleBodyService.update(articleBody)));
    }

    @DeleteMapping("{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable Long id) {
        return ResponseEntity.ok(this.articleBodyService.deleteById(id));
    }
}
